<template>
	<view class="">
		<!-- <w-timer></w-timer> -->
		<!-- <tags v-if="tableInfo" :tableInfo='tableInfo' @ok='SureTags' @endTable='endTable' :user='user' ></tags> -->
		<charge @contentScan='contentScan'></charge>

		<u-toast ref="uToast" />
		<!-- <wr-state ref='mask' icon='checkmark-circle-fill' iconcolor='#52C41A' tags=' ' content="开台成功" @ready='ready'> -->
		</wr-state>
	</view>
</template>

<script>
	import charge from './components/charge.vue';
	import tags from './components/tags.vue'
	import wxpay from '@/common/wxpay.js'
	export default {
		components: {
			charge,
			tags
		},
		data() {
			return {
				tableInfo: '',
				user: '',
				cid: "",
				sid: ''
			}
		},
		onLoad(options) {


			if (options.q) {

				let {
					sid,
					cid
				} = this.$getParams(options.q);
				this.sid = sid;

				this.cid = cid
			}
			this.getTable(this.cid)
			this.getUser()
		},
		onShow() {
			uni.$on("isformBookClick", res => {
				console.log(res, "res")
				this.tableInfo = ''
				this.getTable(this.cid)
				// 清除监听
				uni.$off('isformBookClick');
			})
		},
		methods: {
			getUser() {
				this.$u.api.userInfo().then(res => {
					this.user = res;
				})
			},
			contentScan(e) {
				let {
					sid,
					cid
				} = e;
				this.cid = cid;
				this.sid = sid;

				uni.$emit("isformBookClick", {
					data: 'isformBook'
				});
				this.getTable(cid)
			},
			getTable(cid) {
				this.$u.post('/index/carportDetail', {
					id: cid,
				}).then(res => {
					if (!res.orders) {
						if (res.isAppointment) {
							this.$refs.uToast.show({
								title: '当前台位已经被预约',
								type: 'error',
							})
						} else {
							uni.navigateTo({
								url: "/pages/store/stareDetail?sid=" + this.sid + "&cid=" + this.cid
							})
						}

					} else {
						uni.navigateTo({
							url: "/pages/store/bookStatus?sid=" + this.sid + "&cid=" + this.cid
						})
						// this.tableInfo = res;
						// this.show = true
					}

				})
			},

			SureTags(e) {
				this.$u.post('/indent/orderStart', {
					carport_id: e,
				}).then(res => {
					if (Array.isArray(res)) {
						this.openDesk({
							id: e
						})
					} else {
						const wx = new wxpay(res);
						wx.pay().then(res => {
							this.openDesk({
								id: e
							})
						}).catch(err => {

						})
					}
					this.$refs.mask.show = true
				})
			},
			endTable(e) {
				uni.navigateTo({
					url: '/pages/scan/total?id=' + e
				})
				this.show = false
			},
			openDesk(item) {
				this.$u.post('/index/carportDetail', {
					id: item.id,
				}).then(res => {
					this.tableInfo = res;

				})
			}
		}
	}
</script>

<style>
</style>